#!/bin/sh

# Aladin Bourne shell launcher 
# P.Fernique [CDS] - F.Ochsenbein [CDS]
# V1.1 - oct 2010
# V1.0 - april 2009

# JAVA memory max allocation (in Mb)
mem=1024

# Via a symbolic link ?
prog=$0
while test -h $prog; do
    prog1=`ls -l $prog | awk '{print $NF}'`
    if test `expr $prog1 : /` -gt 0; then       # Absolute symlink
        prog="$prog1"
    else
        prog=`dirname $prog`/$prog1             # Relative symlink
    fi
done

# Aladin launch
java -Xmx${mem}m -jar `dirname $prog`/Aladin.jar -script="setconf Dir=`pwd`;" $*
res=$?

# Pb1: Aladin.jar not found
if [ $res = 1 ]; then
   echo "Aladin and Aladin.jar must be in the same directory"
   
#Pb 2: JAVA not jound
else 
   if [ $res = 127 ]; then
      jvminstall="http://www.java/download"
      browser="mozilla firefox netscape"
      echo "Java Runtime environment not found"
      echo "=> Fix your path or install it ($jvminstall)"
      for w in $browser; do
         $w -remote openURL\($jvminstall\) 2> /dev/null
         if [ $? = 0 ]; then
            exit 0
         fi	 
      done
      for w in $browser; do
         $w $jvminstall 2> /dev/null
         if [ $? = 0 ]; then
            exit 0
         fi	 
      done
   fi
fi

